package com.varian.tool.exception;

import cn.hutool.core.util.ArrayUtil;
import com.varian.tool.contant.ResultConstant;
import lombok.Getter;

/**
 * @author ben
 * @since 2024/6/22
 */
@Getter
public class BizException extends BaseException {

    private final String code;
    private final Object[] params;

    protected BizException() {
        this(ResultConstant.FAIL_CODE);
    }

    protected BizException(String code) {
        this(code, ResultConstant.FAIL.message());
    }

    protected BizException(String code, Object... params) {
        super(ResultConstant.FAIL.status(), ResultConstant.FAIL.message());
        this.code = code;
        this.params = params;
    }

    public static BizException of(String code) {
        return new BizException(code);
    }

    public static BizException of(String code, Object... params) {
        return new BizException(code, params);
    }

    @Override
    public StackTraceElement[] getStackTrace() {
        return ArrayUtil.sub(super.getStackTrace(), 0, 5);
    }
}
